#pragma once
#include "cjb/Jieba.hpp"              // jieba库
#include <boost/algorithm/string.hpp> // boost库
#include <iostream>
#include <fstream>
#include <string>
#include <vector>
#include <unordered_map>
#define ENUMFILE_ERROR 1
#define PARSERHTML_ERROR 2
#define SAVEHTML_ERROR 3
#define OPEN_ERROR 4;

namespace Ns_Util
{
    class FileUtil
    {
    public:
        // Read file to html data
        static bool ReadHtmlFile(const std::string &file_path, std::string *htmldata)
        {
            std::ifstream in(file_path.c_str(), std::fstream::in);
            if (!in.is_open())
            {
                std::cerr << "open file: " << file_path << " error!!!" << std::endl;
                return false;
            }
            std::string line;
            while (getline(in, line))
            {
                *htmldata += line;
            }
            in.close();
            return true;
        }

    private:
    };

    class StringUtil
    {
    public:
        // raw_data: 进行切割的数据，results: 切割完成进行保存，sep：切割分隔符
        static void CutString(const std::string &raw_data, std::vector<std::string> *results, std::string sep)
        {
            // split: 第一个参数是字符串数组，用于保存切割结果，第二个是被切割的文件
            //        第三个是分隔符，第四个是是否压缩内容
            boost::split(*results, raw_data, boost::is_any_of(sep), boost::token_compress_on);
        }
    };

    // 词库路径 -- demo.cpp里面有测试样例
    const char *const DICT_PATH = "./dict/jieba.dict.utf8";
    const char *const HMM_PATH = "./dict/hmm_model.utf8";
    const char *const USER_DICT_PATH = "./dict/user.dict.utf8";
    const char *const IDF_PATH = "./dict/idf.utf8";
    const char *const STOP_WORD_PATH = "./dict/stop_words.utf8";

    // jieba分词接口
    class JiebaUtil
    {
    public:
        // str: 待分词字符串，result: 分词之后保存到这里
        static void StringParticiple(const std::string& str, std::vector<std::string>* result)
        {
            jieba.CutForSearch(str, *result); // 调用jieba分词api
        }
    private:
        static cppjieba::Jieba jieba;  // jieba对象
    };
    cppjieba::Jieba JiebaUtil::jieba(DICT_PATH,HMM_PATH,USER_DICT_PATH,
                                        IDF_PATH, STOP_WORD_PATH);
}